<template>
	<view class="page">
		<u-image show-loading :src="$imageOss(detail.image)" width="100%" height="248px" @click="preImage" />
		<view class="body">
			<Sub-title :label="detail.titile" :line="2" />
			<view class="base">
				<view class="box">
					<view class="" style="display: flex;">
						<u-icon name="eye"></u-icon>
						<view class="">{{detail.read}}</view>
					</view>

					<view class="bot2" style="display: flex;">
						<view class="" style="font-size: 26rpx;color: #466EC5;">
							{{detail.registered}}
						</view>/{{detail.limit}}人
					</view>
				</view>
			</view>
			<view class="age">
				<u-text :text="`年龄要求: ${detail.age}`" lines="1" line-height="48rpx" color="#909090" size="26rpx" />
				<u-text :text="`培训时间: ${detail.train_start_time}-${detail.train_end_time}`" lines="1"
					line-height="48rpx" color="#909090" size="26rpx" />
				<u-text :text="`报名时间: ${detail.application_start_time}-${detail.application_end_time}`" lines="1"
					line-height="48rpx" color="#909090" size="26rpx" />
			</view>
			<view class="addr" @tap.stop="handleMap">
				<view class="" style="margin-right: 6rpx;">
					<u-icon name="map-fill" size="12" color="#909090"></u-icon>
				</view>
				<view class="">
					{{detail.address}}
				</view>
			</view>
			<view class="navBox" style="">
				<view class="item" v-for="(i,index) in typeList" :key="index"
					:style="{color:(tabCurrent == index?'#466EC5':'#000')}" @tap.stop="tabChange(index)">
					<view class="">
						{{i.name}}
					</view>
				</view>
			</view>

			<view class="" style="display: flex;align-items: center;">
				<view class="leftIcon"></view>
				<Sub-title label="课程简介" />
			</view>

			<u-parse :content="detail.message" style="color: #909090;font-size: 26rpx;" />
			<view class="" style="display: flex;align-items: center;">
				<view class="leftIcon"></view>
				<Sub-title label="师资介绍" />
			</view>

			<u-scroll-list style="width: 100% !important;" :indicator="false">
				<view class="tabBox" style="display: flex;justify-content: space-between;background-color: #fff;">
					<view class="navItem" v-for="(i,index) in detail.teacher" :key="index">
						<image :src="$imageOss(i.image)" mode="aspectFill" style="" class="image"></image>
						<view class="bot">
							<text class="bot1">{{i.name}}</text>
						</view>
					</view>
				</view>
			</u-scroll-list>

			<view id="req" style="display: flex;align-items: center;">
				<view class="leftIcon"></view>
				<Sub-title label="报名要求" />
			</view>
			<u-parse :content="detail.application_msg" style="color: #909090;font-size: 26rpx;" />
			<!-- <view class="" style="display: flex;align-items: center;">
				<view class="leftIcon"></view>
				<Sub-title label="评论" />
			</view>
			<remark :page="page" @lastPage="lastPage" v-if="detail.id" :typeId="detail.id" :type="2" :adminId="detail.admin_id" /> -->
		</view>
		<view class="bott">
		<!-- 	<Foot :comment="detail.count" :like="detail.like" :collect="detail.collect" :type="2"
				path="/pages/home/learnDetails" :is_like="detail.is_like" :is_collect="detail.is_collect"
				:is_id="detail.id" @like="handleLike"></Foot> -->

			<view class="button" :style="{background:detail.test == '报名已结束'?'#A9A9AA':'#193980'}"
				@tap.stop="handle(detail)"> {{detail.test}}</view>
		</view>
	</view>
</template>

<script>
	import Foot from "@/components/footer/index";
	import remark from "@/components/remark/index";
	import {
		trainDetail
	} from "@/request/homeApi.js";
	export default {
		components: {
			remark,
			Foot
		},
		data() {
			return {
				tabCurrent: 0, // 当前大类
				typeList: [{
						name: "课程详情",
						id: "0",
					},
					{
						name: "报名要求",
						id: "1",
					}
				],
				detail: {},
				page:1,
				last_page:1

			};
		},
		onLoad(e) {
			this.detail.id = e.id ? e.id : ''
			this.getDetails(this.detail.id);
		},
		computed: {

		},
		onReachBottom() {
			let that = this
			if (that.page < that.last_page) {
				that.page = that.page + 1
			}
		},
		// 监听页面滚动
		onPageScroll(scroll) {
			uni.$emit("onPageScroll", scroll.scrollTop);
		},
		methods: {
			lastPage(e){
				this.last_page = e
			},
			
			// 点赞/收藏
			handleLike(v) {
				this.getDetails(v)
			},
			shareClick() {
				this.share = {
					title: '',
					path: `/pages/home/learnDetails?id=${this.detail.id}`,
					imageUrl: '',
					desc: '',
					content: ''
				}
			},

			// tab 切换
			tabChange(e) {
				this.tabCurrent = e
				if (this.tabCurrent == 1) {
					uni.pageScrollTo({
						selector: '#req', //你要跳转的样式位置
						duration: 300, //跳转时间段
					})
				}
			},
			Jump(url) {
				uni.navigateTo({
					url: url
				})
			},
			// 预览图片
			preImage() {
				uni.previewImage({
					urls: [this.detail.cover_img],
				});
			},
			// 点击拨号
			callPhone() {
				uni.makePhoneCall({
					phoneNumber: this.detail.phone,
				});
			},
			// 跳转地图
			handleMap() {

				// let result = this.$store.dispatch("permission/requestPermissions",
				// 	'ACCESS_FINE_LOCATION')
				// if (result !== 1) return
				const {
					lat,
					lng,
					address
				} = this.detail;
				uni.openLocation({
					latitude: lat,
					longitude: lng,
					address: address,
					scale: 16,
				});
				uni.navigateTo({
					url: `/pages/parse/map?lat=${lat}&lng=${lng}`
				});
			},
			// 获取详情
			getDetails(id) {
				let that = this
				trainDetail({
					id
				}).then((res) => {
					if (res.code == 200) {
						that.detail = res.data;
					} else {
						uni.showToast({
							title: res.msg,
							duration: 1500,
							icon: 'none',
						})
					}
				});
			},
			// 报名
			handle(e) {
				if (e.test.indexOf("结束", 0) != -1) {
					uni.showToast({
						title: e.test,
						icon: "none",
					});
					return;
				}
				if (e.test.indexOf("进行", 0) != -1) {
					uni.showToast({
						title: e.test,
						icon: "none",
					});
					return;
				}

				if (this.detail.registered == this.detail.limit) {
					uni.showToast({
						title: '报名已达上限',
						icon: "none",
					});
					return;
				}
				uni.navigateTo({
					url: `/pages/home/applyDetails?id=${e.id}&type=train&nickname=${e.titile}`,
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	.page {
		button::after {
			border: none;
		}

		.button-hover {
			background: #fff;
		}

		.leftIcon {
			width: 6rpx;
			height: 30rpx;
			margin-right: 10rpx;
			background: #47578E;
		}

		.navBox {
			display: flex;
			justify-content: space-evenly;
			width: 50%;
			padding: 10rpx 0;
			box-sizing: border-box;
			font-size: 30rpx;

			.item {
				width: 49.83% !important;
				text-align: left !important;
			}
		}

		.bott {
			position: fixed;
			bottom: 0;
			left: 0;
			height: 110rpx;
			background: #fff;
			width: 100%;
			display: flex;
			align-items: center;
			padding: 30rpx 40rpx 40rpx;
			justify-content: space-between;
			box-shadow: 0 0 10rpx rgba(228, 228, 228, 0.5);
			box-sizing: border-box;
			z-index: 2;

			.button {
				width: 95%;
				height: 70rpx;
				padding: 0 28rpx;
				box-sizing: border-box;
				margin-left: 20rpx;
				text-align: center;
				line-height: 70rpx;
				color: #fff;
				font-size: 28rpx;
				background-color: $active-color;
				border-radius: 10rpx;
			}
		}

		.body {
			width: 94%;
			// padding: 20rpx 24rpx;
			min-height: 100rpx;
			box-sizing: border-box;
			background-color: #ffffff;
			margin-top: -14rpx;
			padding-bottom: 140rpx;
			margin: 20rpx 24rpx;

			.age {
				padding: 20rpx 0;
				border-bottom: 2rpx solid #D9D9D980;
			}

			.addr {
				display: flex;
				align-items: center;
				justify-content: flex-start;
				font-size: 26rpx;
				padding: 16rpx 0;
				color: #909090;
			}

			.base {
				.box {
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-size: 24rpx;
					color: #B6B6B6;
					padding-bottom: 20rpx;
					border-bottom: 2rpx solid #D9D9D980;
				}
			}

			.tabBox {
				width: 100%;
				box-sizing: border-box;
				font-size: 30rpx;

				.navItem {
					padding: 10rpx 20rpx 0;
					width: 24.33%;
					text-align: center;
					box-sizing: border-box;

					.image {
						width: 100rpx;
						height: 100rpx;
						border-radius: 50%;
					}
				}
			}

			.remarkBox {
				width: 100%;
				box-sizing: border-box;
				font-size: 28rpx;
				color: #909090;

				.navItem {
					width: 98%;
					text-align: center;
					box-sizing: border-box;
					display: flex;
					align-items: center;
					margin: 20rpx auto;

					.image {
						width: 56rpx;
						height: 56rpx;
						border-radius: 50%;
						margin-right: 16rpx;
					}
				}
			}


			.card-item {
				width: 100%;
				height: 240rpx;
				margin: 10rpx 0;
				background-size: 100% 100%;
				padding: 0 40rpx;
				display: flex;
				box-sizing: border-box;
				align-items: center;

				>view:first-child {
					flex: 1;
				}

				>view:last-child {
					width: 172rpx;
					height: 140rpx;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: space-around;

					.price {
						color: #ff3e3e;

						>text:first-child {
							font-size: 28rpx;
						}

						>text:nth-child(2) {
							font-size: 24rpx;
						}

						>text:last-child {
							font-size: 40rpx;
						}
					}

					.btn {
						width: 172rpx;
						height: 56rpx;
						color: #fff;
						font-size: 28rpx;
						line-height: 56rpx;
						text-align: center;
						border-radius: 28rpx;
						background-color: $active-color;
					}

					.disabled {
						color: #f9f9f9;
						background-color: #dbdbdb;
					}
				}
			}
		}
	}
</style>
